package com.aoip.telemetry.telemetry.entity.common;

import com.aoip.telemetry.telemetry.entity.equipment.StInfoConfigEntity;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 测站每日上报统计实体
 *
 * @author chenbai
 * @version 1.0
 * @date 2022/1/7 16:10
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Builder
@TableName("st_report_statistics")
@ApiModel(description = "元素解析组配置表")
public class ReportStatisticsEntity implements Serializable {
    private static final long serialVersionUID = 4504952298872387861L;

    @TableField(value = "st_cd")
    @ApiModelProperty("测站编码")
    private String stCd;

    @TableField(value = "statistic_time")
    @ApiModelProperty("统计时间")
    private LocalDate statisticTime;

    @TableField(exist = false)
    @ApiModelProperty("开始统计时间")
    private String beginStatisticTimeCn;

    @TableField(exist = false)
    @ApiModelProperty("开始统计时间")
    private LocalDate beginStatisticTime;

    @TableField(exist = false)
    @ApiModelProperty("结束统计时间")
    private String endStatisticTimeCn;

    @TableField(exist = false)
    @ApiModelProperty("结束统计时间")
    private LocalDate endStatisticTime;

    @TableField(value = "should_amount")
    @ApiModelProperty("应上报数据条数")
    private Integer shouldAmount;

    @TableField(value = "actual_amount")
    @ApiModelProperty("实际上报数据条数")
    private Integer actualAmount;

    @TableField(value = "report_rate")
    @ApiModelProperty("数据上报率")
    private Integer reportRate;

    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @ApiModelProperty("创建时间")
    private LocalDateTime createTime;

    @TableField(exist = false)
    @ApiModelProperty("接入测站信息实体")
    private StInfoConfigEntity stInfoConfigEntity;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    public LocalDate getStatisticTime() {
        return statisticTime;
    }

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    public void setStatisticTime(String time) {
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        this.statisticTime = LocalDate.parse(time, dtf);
    }
}
